package com.fastfood.model.blo;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.fastfood.model.dao.RoleDAO;
import com.fastfood.model.dto.Role;
import com.fastfood.util.DBConnectionPool;

public class RoleBLO {

	private RoleDAO dao = new RoleDAO();
	
	public List<Role> getAllRoles() {
		List<Role> roles = null;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			roles = dao.getAllRoles(conn);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return roles;
	}
	
	public boolean addRole(Role role) {
		boolean result = false;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			result = dao.addRole(conn, role);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public boolean updateRole(Role role) {
		boolean result = false;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			result = dao.updateRole(conn, role);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public boolean deleteRole(Role role) {
		boolean result = false;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			result = dao.deleteRole(conn, role);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}	
}
